using System;
using System.Web;
using System.Xml;
using System.Xml.Xsl;

using umlungu.engineX.emailX;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington	
	Started:	2006-03-08	
	Status:		release	
	Version:	2.0.0
	Build:		20071123
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/

/*	---------------------------------------------------------------------------	
	Development Notes:
	==================
	20070524:	Modification for .Net 2.0
	20071123:	Replaced x_email with EmailX.x_email
	---------------------------------------------------------------------------	*/

namespace umlungu.engineX.blogX {
	/// <summary>
	/// x_provider class.
	/// <para>This class is a 'provider' for a request on a site using the displayX class to display a page</para>
	/// <para>Note the following:</para>
	/// <para>- Respond to a request and process the Form or Querystring parameters of the request</para>
	/// <para>- They get passed the page itself (the displayX object) and can access the page properties/methods</para>
	/// <para>- The base class has a _Process method to send a html email of a form's fields</para>
	/// <para>- </para>
	/// <para>- </para>
	/// </summary>
	public class x_provider : x_actor {
		#region Invisible properties
		private const string error_form_send = "Form email sending error: ";
		#endregion

		#region Visible properties
		#endregion

		#region Constructors/Destructors
		/// <overloads>Constructor</overloads>
		/// <summary>Default constructor</summary>
		/// <param name="thispage">The web application Page object</param>
		public x_provider(displayX thispage) : base(thispage) {
		}
		#endregion

		#region Public methods
		///	<overloads>Provider processing method</overloads>
		/// <summary>
		/// Does the provider processing of the page content. 
		///	This method is typically overriden in derived classes in order to load content or process the page content.
		///	Example: this method can be overridden by a method that calls a web service and appends xml to the page.
		/// </summary>
		public override void Act() {
			_SendForm();
		}
		#endregion
		
		#region Protected methods
		///	<overloads>Emails a submitted form</overloads>
		/// <summary>To the configured email address</summary>
		protected void _SendForm() {
			try {
				x_email thisemail = new x_email();
				/* html...*/
				thisemail.Type = x_emailtype.html;
				thisemail.Send(UIPage.Request, _GetTemplate("emailX.xsl"));
				/* xml or text...
				thisemail.Type = x_emailtype.xml;
				thisemail.Send(UIPage.Request);
				*/
				/* text...
				thisemail.Message = String.Concat("\nType: ", feedbackScore, "\nTitle: ", contactTitle, "\nName: ", contactName, "\nEmail: ", contactEmail, "\nTelephone: ", contactTelno, "\nCellphone: ", contactCellno, "\nQuery: ", feedbackText);
				thisemail.Send();
				*/
			}
			catch(System.Exception e) {
				throw(new x_exception("error_form_send", String.Concat(error_form_send, e.Message)));
			}
		}
		/// <summary>To the configured email address with subject line</summary>
		///	<param name="subj">The subject line of the email</param>
		protected void _SendForm(string subj) {
			try {
				x_email thisemail = new x_email();
				thisemail.Subject = subj;
				thisemail.Type = x_emailtype.html;
				thisemail.Send(UIPage.Request, _GetTemplate("emailX.xsl"));
			}
			catch(System.Exception e) {
				throw(new x_exception("error_form_send", String.Concat(error_form_send, e.Message)));
			}
		}
		/// <summary>To the configured email address with subject line</summary>
		///	<param name="subj">The subject line of the email</param>
		///	<param name="bcc">The bcc address of the email</param>
		protected void _SendForm(string subj, string bcc) {
			try {
				x_email thisemail = new x_email();
				thisemail.Subject = subj;
				thisemail.Bcc = bcc;
				thisemail.Type = x_emailtype.html;
				thisemail.Send(UIPage.Request, _GetTemplate("emailX.xsl"));
			}
			catch(System.Exception e) {
				throw(new x_exception("error_form_send", String.Concat(error_form_send, e.Message)));
			}
		}
		#endregion
				
		#region Private methods
		#endregion
	}
}
